package com.wxzz.elearing.pay.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.wxzz.elearing.pay.entity.PlatformLivetelecastOrderData;
import com.wxzz.elearing.pay.vo.PlatformLivetelecastOrderDataVo;
import com.wxzz.elearning.common.dto.ActivityStatisticsDto;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.math.BigDecimal;
import java.util.List;

public interface PlatformLivetelecastOrderDataMapper extends BaseMapper<PlatformLivetelecastOrderData> {

    @Select("SELECT\n" +
            "\tbusiness_id,\n" +
            "\tSUM( income_price ) incomePrice\n" +
            "FROM\n" +
            "\t`user_order` \n" +
            "WHERE\n" +
            "\tcreate_time > #{startTime} \n" +
            "\tAND create_time < #{endTime} \n" +
            "\tAND order_status = 1 \n" +
            "\tAND model_type = #{modelType} AND deleted = 0 \n" +
            "GROUP BY\n" +
            "\tbusiness_id")
    List<PlatformLivetelecastOrderDataVo> selectPlatformLivetelecastOrderDataVo(@Param("startTime") String startTime,
                                                                                @Param("endTime") String endTime,
                                                                                @Param("modelType") Integer modelType);

    @Select("SELECT\n" +
            "\tSUM( amount ) \n" +
            "FROM\n" +
            "\t`platform_livetelecast_order_data` \n" +
            "WHERE\n" +
            "\tplatform_livetelecast_id = #{activityId} \n" +
            "\tAND online_type = #{onlineType} AND deleted = 0 ")
    BigDecimal selectCountAmount(@Param("activityId") Long activityId, @Param("onlineType") Integer onlineType);

    @Select("SELECT\n" +
            "\tsave_time saveTime,\n" +
            "\tSUM( amount ) amount\n" +
            "FROM\n" +
            "\t`platform_livetelecast_order_data` \n" +
            "WHERE\n" +
            "\tplatform_livetelecast_id = #{platformLivetelecastId} \n" +
            "\tAND deleted = 0 \n" +
            "GROUP BY\n" +
            "\tsave_time \n" +
            "ORDER BY\n" +
            "\tsave_time ASC")
    List<ActivityStatisticsDto> selectActivityStatisticsDto(@Param("platformLivetelecastId")Long platformLivetelecastId);
}
